<?php
use think\facade\Db;
 
class userRegister{
    public function TODO($frame,$fd){
        
        $param = (array)json_decode($frame->data); 
        $data = [
            'pass'  =>   md5($param['passwd']), 
            'uuid'  =>   uuid_create(1),  
            'tokenId'   => self::createToken(),
            'expireTime'   => time(), 
            'fd'        =>  $fd,
            'username' => $param['username']
        ];
 
 
        $isEmpty = Db::name('user')->where('username',$param['username'])->find();
        var_dump($isEmpty);
        // $db->query($collname, $filter, $queryWriteOps)->toArray(); 
        
        if(empty($isEmpty)){
            $rs = Db::name('user')->insert($data);
            if($rs){
                $return = [
                    'status'=>0,
                    'msg'=>'注册成功,请进行登录',
                    'data'=>'', 
                    'act'=>'userRegister',
                    'fd'=>$fd,
                ];
            }else{
               $return = [
                'status'=>0,
                'msg'=>'注册失败',
                'data'=>'',
                'act'=>''
                ]; 
            }
        }else{
            $return = [
                'status'=>0,
                'msg'=>'该账户已存在',
                'data'=>'', 
                ];
        }
        return $return;
    }
    public static function createToken(){
        return md5(mt_rand().microtime());
    }
}